home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / x3270 / unix_files / Examples / peer_script.bash < prev    next >
Encoding:
Text File  |  2008-08-17  |  2.3 KB  |  134 lines

  1. #! /bin/bash
  2. # TSO login script, which runs as a peer of x3270.
  3. # bash version
  4.  
  5. set -x
  6. me=${0##*/}
  7.  
  8. # Set up login parameters
  9. tcp_host=${1-ibmsys}
  10. dial_user=${2-VTAM}
  11. sna_host=${3-TSO}
  12. userid=${4-USERID}
  13. password=${5-PASSWORD}
  14.  
  15. # Verbose flag for x3270if
  16. #v="-v"
  17.  
  18. # Define some handly local functions.
  19.  
  20. # x3270 interface function
  21. function xi
  22. {
  23.     X3270OUTPUT=6 X3270INPUT=5 x3270if 5>$ip 6<$op $v "$@"
  24. }
  25.  
  26. # Common x3270 Ascii function
  27. function ascii
  28. {
  29.     xi 'Ascii('$1')'
  30. }
  31.  
  32. # Common x3270 String function
  33. function string
  34. {
  35.     xi 'String("'"$@"'")'
  36. }
  37.  
  38. # x3270 cursor column
  39. function cursor_col
  40. {
  41.     xi -s 10
  42. }
  43.  
  44. # x3270 connection status
  45. function cstatus
  46. {
  47.     xi -s 4
  48. }
  49.  
  50. # Failure.
  51. function die
  52. {
  53.     xi "Info(\"$me error: $@\")"
  54.     xi "CloseScript(1)"
  55.     exit 1
  56. }
  57.  
  58. # Set up pipes for x3270 I/O
  59. ip=/tmp/ip.$$
  60. op=/tmp/op.$$
  61. rm -f $ip $op
  62. trap "rm -f $ip $op" EXIT
  63. trap "exit" INT QUIT HUP TERM
  64. mknod $ip p
  65. mknod $op p
  66.  
  67. # Start x3270
  68. x3270 -script -model 2 <$ip >$op &
  69. xp=$!
  70. exec 5>$ip    # hold the pipe open
  71. xi -s 0 >/dev/null || exit 1
  72.  
  73. # Connect to host
  74. xi "Connect($tcp_host)" || die "Connection failed."
  75.  
  76. # Make sure we're connected.
  77. xi Wait
  78. [ "$(cstatus)" = N ] && die "Not connected."
  79.  
  80. # Get to a VM command screen
  81. xi Enter
  82.  
  83. # Wait for VM's prompt
  84. while [ "$(ascii 1,0,5)" != "Enter" ]
  85. do    sleep 2
  86. done
  87.  
  88. # Dial out to VTAM
  89. string "DIAL $dial_user"
  90. xi Enter
  91. typeset -i sl=10+${#dial_user}
  92. typeset -i dl=5+${#dial_user}
  93. while [ "$(ascii 0,64,4)" != VTAM ]
  94. do    s="$(ascii 8,0,$sl | sed 's/^ *//')"
  95.     if [ "$s" != "DIALED TO $dial_user" -a "$s" != "" ]
  96.     then    if [ "$(ascii 7,0,$dl)" = "DIAL $dial_user" ]
  97.         then    die "Couldn't get to VTAM"
  98.         fi
  99.     fi
  100.     sleep 2
  101. done
  102.  
  103. # Get to the SNA host
  104. string "$sna_host $userid"
  105. xi Enter
  106.  
  107. # Pass VTAM digestion message and initial blank TSO screen
  108. while [ "$(ascii 0,21,20)" = "USS COMMAND HAS BEEN" ]
  109. do    sleep 2
  110. done
  111. while :
  112. do    s="$(ascii 0,33,11 | sed 's/^ *//')"
  113.     [ "$s" != "" ] && break
  114.     sleep 2
  115. done
  116.  
  117. # Now verify the "TSO/E LOGON" screen
  118. [ "$s" = "TSO/E LOGON" ] || die "Couldn't get to TSO logon screen"
  119.  
  120. # Pump in the password
  121. string "$password"
  122. xi Enter
  123.  
  124. # Now look for "LOGON IN PROGRESS"
  125. typeset -i nl=18+${#userid}
  126. [ "$(ascii 0,11,$nl)" = "$userid LOGON IN PROGRESS" ] || die "Couldn't log on"
  127.  
  128. # Make sure TSO is waiting for a '***' enter
  129. [ "$(cursor_col)" -eq 5 ] || die "Don't understand logon screen"
  130.  
  131. # Off to ISPF
  132. xi Enter
  133. xi 'CloseScript(0)'
  134.